<?php
namespace app\index\controller;

use think\Controller;
use app\index\model\Staff;
use app\index\model\BasicData;
use app\index\model\LeaveRecord;
use app\index\model\Interview;

class Index extends Controller
{
    public function index()
    {
    	$this -> view -> engine -> layout('layout/layout');
    	return $this -> fetch();
    }
    public function indexframe() {
    	return $this -> fetch();
    }
    public function hello()
    {
        return 'hello,';
    }
    public function demoAjax() 
    {
    	return ['status' => 1,'msg' =>'这是通过ajax返回的数据'];
	}
	public function homepage()
	{
	    return $this -> fetch();
	}
	/*
	 * 首页数据统计
	 * */
	public function dataStatistics()
	{
	    $data = array();
	    $staffModel = new Staff();
	    //在职员工数
	    $data['payrollNum'] = $staffModel -> getStaff();
	    $BDmodel = new BasicData();
	    //邀请面试数量 月 周 
	    $data['inviteNum'] = $BDmodel -> getInvite();
	    //每周 每月 入职量 
	    $data['entryNum'] = $staffModel -> getEntry($state='1,2,3');
	    //每周 每月离职数量
	    $data['quitNum'] = $staffModel -> getEntry($state='4');
	    return json(['msg' => "加载成功..",'data' => $data]);
	}
	/*
	 * 首页入职统计
	 * */
	public function entryStatistics()
	{
	    $didStr = input('did');
	    $did = explode(',', $didStr);
	    $status = 1;
	    $BDmodel = new BasicData();
	    $data = $BDmodel -> personnelFlow($did,$status,input('beginMonth'),input('endMonth'));
	    return json(['msg' => "加载成功..",'data' => $data]);
	}
	/*
	 * 首页请假统计
	 * */
	public function leaveStatistics()
	{
	    $didStr = input('post.did')?:'1,2,3';
	    $did = explode(',',$didStr);
	    $LRmodel = new LeaveRecord();
	    $data = $LRmodel -> getLeave($did,"2018-01","2018-08");
	    return json(['msg' => "加载成功..",'data' => $data]);
	}
	/*
	 * 今日档案  
	 * */
	public function basicData()
	{
	    $BDmodel = new BasicData();
	    $data = $BDmodel -> todayBasicdata();
	    if(!$data) {
	        return json(['msg' =>$BDmodel->getError()]);
	    }
	    return json(['msg' => "加载成功..",'data' => $data]);
	}
	/*
	 * 请假记录
	 * */
	public function getLeaveData()
	{
	    $LRmodel = new LeaveRecord();
	    $data = $LRmodel -> getLeaveRecord();
	    if(!$data) {
	        return json(['msg' =>$LRmodel->getError()]);
	    }
	    return json(['msg' => "加载成功..",'data' => $data]);
	}
	/*
	 * 获取待面试  已面试 面试通过  淘汰  的表格数据
	 * */
	public function getAudition()
	{
	    //获取是待面试还是已面试
	    $status = input('post.status/d');
	    //获取面试通过还是淘汰
	    $results = input('results/d');
	    //登录人ID
	    $sid = 1;
	    $IVmodel = new Interview();
	    $data = $IVmodel -> getAuditionData($sid,$status,$results);
	    if(!$data) {
	        return json(['msg' =>'暂无数据']);
	    }
	    return json(['msg' => "加载成功..",'data' => $data]);
	}
	/*
	 * 待我面试
	 * */
	public function audition()
	{
	    return $this -> fetch();
	}
	
	/*
	 * 面试评价
	 * */
	public function evaluate()
	{
	    return $this -> fetch();
	}
	/*
	 * 已面试
	 * */
	public function already()
	{
	    return $this -> fetch();
	}

	/*
	 * 转正
	 * */
	public function promotion()
	{
	    return $this -> fetch();
	}
}
